#include "core/config.h"

namespace core {
	namespace po = boost::program_options;

	Config::Config():
		System("Config", Task::NONE)
	{
	}

	Config::~Config() {
	}

	po::options_description& Config::settings() {
		return mOptions;
	}

	bool Config::load(const std::string& name) {
		std::ifstream ifs(name.c_str());
		
		if (!ifs) {
			mLog << "Failed to open config file: " << name;
			
			return false;
		}
		else {
			po::store(po::parse_config_file(ifs, mOptions, true), mVariables);
			po::notify(mVariables);
			return true;
		}
	}

	void Config::parseCommandLine(int argc, char* argv[]) {
		po::store(po::parse_command_line(argc, argv, mOptions), mVariables);
		mVariables.notify();
	}

	bool Config::isSet(const std::string& name) const {
		return (mVariables.count(name) > 0);
	}
}
